package cn.hh.basic.config;

import cn.hh.basic.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *  当前类是一个配置类 - 用于替换以前的xml配置
 */
@Configuration
public class MyWebConfig implements WebMvcConfigurer{

    @Autowired // 注入 - 前提 - 容器中有该类型或子类型的对象
    private LoginInterceptor loginInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截器
        registry.addInterceptor(loginInterceptor)
                // 拦截什么请求
                .addPathPatterns("/**") // 拦截所有请求
                // 放行: 跟登录相关 或 注册相关的都要请求放行
                .excludePathPatterns("/login/**")  // 登录相关请求
                .excludePathPatterns( "/user/*/Register","/verifyCode/**","/shop/settlement","/fastdfs")  // 放行注册相关请求
                .excludePathPatterns("/swagger-resources/**","/webjars/**","/v2/**","/swagger-ui.html/**");
                // 放行邮箱激活


    }
}
